<?php

/**
 * This is the model class for table "user_access".
 *
 * The followings are the available columns in table 'user_access':
 * @property integer $user_id
 * @property string $user_firstname
 * @property string $user_lastname
 * @property string $user_address
 * @property string $user_contactno
 * @property string $user_email
 * @property string $user_username
 * @property string $user_password
 *
 * The followings are the available model relations:
 * @property Reservation[] $reservations
 */
class UserRegistration extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return UserRegistration the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'user_access';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_firstname, user_lastname, user_address, user_contactno, user_email, user_username, user_password', 'required'),
			array('user_firstname, user_lastname, user_contactno, user_username, user_password', 'length', 'max'=>45),
			array('user_address, user_email', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_id, user_firstname, user_lastname, user_address, user_contactno, user_email, user_username, user_password', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'reservations' => array(self::HAS_MANY, 'Reservation', 'user_access_user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_id' => 'User',
			'user_firstname' => 'Firstname',
			'user_lastname' => 'Lastname',
			'user_address' => 'Address',
			'user_contactno' => 'Contact Number',
			'user_email' => 'Email Address',
			'user_username' => 'Username',
			'user_password' => 'Password',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('user_firstname',$this->user_firstname,true);
		$criteria->compare('user_lastname',$this->user_lastname,true);
		$criteria->compare('user_address',$this->user_address,true);
		$criteria->compare('user_contactno',$this->user_contactno,true);
		$criteria->compare('user_email',$this->user_email,true);
		$criteria->compare('user_username',$this->user_username,true);
		$criteria->compare('user_password',$this->user_password,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}